package com.dingwen.treasure.model.entity.mybatisplus;

import com.baomidou.mybatisplus.annotation.SqlCondition;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.dingwen.treasure.base.enums.GenderEnum;
import com.dingwen.treasure.base.enums.StatusEnum;
import com.ejlchina.searcher.bean.DbIgnore;
import com.fasterxml.jackson.annotation.JsonIgnore;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.*;
import lombok.experimental.Accessors;

import java.time.LocalDateTime;

/**
 * 系统用户表: TODO @SearchBean(dataSource="slave") 数据源问题等待确认解决
 *
 * @author dingwen
 * @date 2022/04/30
 */
@ApiModel(value = "sysUser", description = "系统用户表")
@TableName("sys_user")
@Accessors(chain = true)
@AllArgsConstructor
@NoArgsConstructor
@Data
@EqualsAndHashCode(callSuper = false)
public class SysUser extends BaseEntity {

    private static final long serialVersionUID = -599399971783079138L;

    /**
     * 主键ID: 数据库自增，已统一配置 </br>
     */
    @ApiModelProperty(value = "用户ID，主键")
    @TableId
    private Long id;

    /**
     * 账号 (用户名、邮箱、电话等)
     */
    @ApiModelProperty(value = "用户名（登录名称）")
    private String account;


    /**
     * 昵称: 模糊匹配
     */
    @ApiModelProperty(value = "昵称")
    @TableField(condition = SqlCondition.LIKE)
    private String nickname;

    /**
     * 密码 </br>
     * <pre>
     *   1.  @TableField(select = false)  Security 校验密码空: @JsonIgnore Jackson 序列化是忽略（返回前端数据忽略,完全忽略会导致 @JsonIgnore feign 调用导致密码缺失）
     *       目前方案返回时密码使用 "*****显示，或者 vo处理"
     *   2.  @DbIgnore 指定 bean search 忽略字段 
     *
     * </pre>
     */
    @ApiModelProperty(value = "密码")
    @DbIgnore
    @JsonIgnore
    private String password;


    /**
     * 性别枚举 {@link GenderEnum} </br>
     */
    @ApiModelProperty(value = "性别", dataType = "GenderEnum")
    private GenderEnum gender;


    /**
     * 最后登录时间 </br>
     * <pre>
     *    1. @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")  (序列化、反序列化 时间格式化)
     *       统一配置
     *       <code>
     *           spring:
     *             jackson:
     *              date-format: yyyy-MM-dd HH:mm:ss
     *              time-zone: GMT+8
     *              default-property-inclusion: always
     *       </code>
     * </pre>
     */
    @ApiModelProperty(value = "最后登录时间")
    @TableField
    private LocalDateTime lastLoginTime;


    /**
     * 状态枚举 {@link StatusEnum}
     */
    @ApiModelProperty(value = "用户状态", dataType = "StatusEnum")
    private StatusEnum status;


    /**
     * toBuilder = true： 可修改
     *
     * @param createTime
     * @param updateTime
     * @param deleted
     * @param version
     * @param createBy
     * @param updateBy
     * @param remark
     */
    @Builder(toBuilder = true)
    public SysUser(LocalDateTime createTime, LocalDateTime updateTime, Integer deleted, Integer version, String createBy, String updateBy, String remark, Long id, String account, String nickname, String password, GenderEnum gender, LocalDateTime lastLoginTime, StatusEnum status) {
        super(createTime, updateTime, deleted, version, createBy, updateBy, remark);
        this.id = id;
        this.account = account;
        this.nickname = nickname;
        this.password = password;
        this.gender = gender;
        this.lastLoginTime = lastLoginTime;
        this.status = status;
    }
}
